using System;
using System.Collections.Generic;
using System.Text;
using System.Reflection;
using System.Windows.Forms;

using SBPweb.Modules.Modularity;
using SBPweb.Contracts;
using SBPweb.Contracts.Options;
using SBPweb.Localization;

// This alias is needed for the module loader to recognize the module's entry point
[assembly: AssemblyDefaultAlias("SBPweb.Modules.ModuleExplorer.ModuleExplorerModule")]

namespace SBPweb.Modules.ModuleExplorer
{
	public class ModuleExplorerModule: ModuleBase
	{

		#region Protected fields

		IOptionsService pOptionsService = null;
		ModuleExplorerOptionsControl pModuleExplorerOptionsControl =null;

		#endregion

		#region Constructor logic

		public ModuleExplorerModule(IModuleHost host)
			: base(host)
		{
			Name = "SBPweb.Modules.ModuleExplorer";
			pAsyncLoad = false;
        
            /*
            SBPweb.Data.Entity.RegisterEntityTypeToFactory<IClass2>(typeof(Class2));

            Class1 c1 = new Class1();
            c1.SetValue<string>("p", "fasza");

            Class2 c2 = (Class2)SBPweb.Data.Entity.CreateInstanceClone<IClass2>(c1);

            string s = c2.GetValue<string>("p");
            */
        }

		#endregion

		#region Public override methods

		public override void Initialize()
		{
			try
			{
				pOptionsService = Services.Get<IOptionsService>();
				pModuleExplorerOptionsControl = new ModuleExplorerOptionsControl(pOptionsService, Host.ModuleLoader);
				pOptionsService.AddOptionsTab("Module explorer", LocalizationExtender.GetString(pModuleExplorerOptionsControl, "Title"), pModuleExplorerOptionsControl);
				pModuleExplorerOptionsControl.Dock = DockStyle.Fill;
			}
			catch { }

			Host.LogManager.WriteVerbose(this, "ModuleExplorer initialized", "ModuleExplorer");
		}


		public override void Terminate()
		{
			if (pOptionsService != null)
			{
				pOptionsService.RemoveOptionsTab("Module explorer");
				pModuleExplorerOptionsControl.Dispose();
			}
		}

		public override void SavePersistency()
		{
		}

		public override void LoadPersistency()
		{
		}

		#endregion

	}
}
